package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.AuthorMapper;
import com.heima.article.service.AuthorService;
import com.heima.model.article.pojos.ApAuthor;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.stereotype.Service;
import sun.invoke.util.Wrapper;

import java.io.Serializable;
import java.util.Date;

@Service
public class AuthorServiceImpl extends ServiceImpl<AuthorMapper, ApAuthor> implements AuthorService {
    /**
     * 根据用户id查询作者信息
     *
     * @param id
     * @return
     */
    @Override
    public ApAuthor findByUserId(Integer id) {
        LambdaQueryWrapper<ApAuthor> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(ApAuthor::getUserId,id);
        ApAuthor author = getOne(wrapper);
        if (author!=null){
            return author;
        }
        return null;
    }

    /**
     * 保存作者
     *
     * @param apAuthor
     * @return
     */
    @Override
    public ResponseResult insert(ApAuthor apAuthor) {
        apAuthor.setCreatedTime(new Date());
        save(apAuthor);
        return ResponseResult.errorResult(AppHttpCodeEnum.SUCCESS);
    }
}
